package dal

import (
	. "7qule.com/sd3/CrossServer/src/bll/kuangzhan/model"
	baseDal "7qule.com/sd3/CrossServer/src/dal"
)

// 镖局Model访问结构
type baseKuangzhanModelDal struct{}

// 访问结构对象
var BaseKuangzhanModelDal = new(baseKuangzhanModelDal)

// 初始化
func init() {
	// 注册到同步对象中
	baseDal.GetSyncMgr().RegisterSyncObj(BaseKuangzhanModelDal.TableName())
}

// TableName 表名
func (this *baseKuangzhanModelDal) TableName() string {
	return "b_kuangzhan_model"
}

// GetData 从数据库获取配置数据
// dataContainer:镖局对象
// 返回值:
// interface{}:获取到的数据
// error:错误信息
func (this *baseKuangzhanModelDal) GetData() ([]*BaseKuangzhanModel, error) {
	sql := "SELECT `LayerId`,`PositionId`,`ColorLv`,`ScoreOut`,`ResourceOut`,`ExpOut` FROM `b_kuangzhan_model`;"

	db := baseDal.GetGameDB().DB()
	execResult, err := db.Query(sql)
	if err != nil {
		baseDal.WriteLog("BaseKuangzhanModelDal", err)

		return nil, err
	}

	defer execResult.Close()

	// 读取数据
	var result = make([]*BaseKuangzhanModel, 0, 16)
	for execResult.Next() {
		var tempNewItem = NewBaseKuangzhanModel2()
		err = execResult.Scan(
			&tempNewItem.LayerId,
			&tempNewItem.PositionId,
			&tempNewItem.ColorLv,
			&tempNewItem.ScoreOut,
			&tempNewItem.ResourceOut,
			&tempNewItem.ExpOut)

		if err != nil {
			baseDal.WriteLog("BaseKuangzhanModelDal", err)
			return nil, err
		}

		result = append(result, tempNewItem)
	}
	return result, nil
}
